/*
 * SeparatedCGOptimizerForACM_FA.cpp
 *
 *      Author: Jerome RD Soine and Christoph A Brand
 *      Institution: Schwarz goup, Institute for Theoretical Physics, Heidelberg University, Germany
 */

#include "SeparatedCGOptimizerForACM_FA.h"
#include "include/base/cell_models/ACM/ActiveCableModel_FA.h"

void SeparatedCGOptimizerForACM_FA::write_FA_state_file(Worker * w){
	stringstream ss;
	ss << tot_iterations;
	ofstream out ((solution_folder+"/"+ss.str()+"_FA_state.txt").c_str());
	out << "# 1 FA index <TAB> 2 FA_area <TAB> 3 FA_orientation <TAB> 4 semi-major axis <TAB> 5 semi-minor axis <TAB> 6 linear eccentricity <TAB> 7 eccentricity <TAB> 8 F_X [nN] <TAB> 9 F_Y [nN] <TAB> 10 abs(F) [nN] <TAB> 11 is connected to SF? <TAB> 12 # connected SFs <TAB> 13 is connected to DSF? <TAB> 14 # connected DSFs <TAB> 15 is connected to VSF? <TAB> 16 # connected VSFs <TAB> 17 is connected to TVA? <TAB> 18 # connected TVAs <TAB> 19 center X <TAB> 20 center Y <TAB> 21 is connected to ending SF? <TAB> 22 # connected ending SFs <TAB> 23 is connected to ending DSF? <TAB> 24 # connected ending DSFs <TAB> 25 is connected to ending VSF? <TAB> 26 # connected ending VSFs <TAB> 27 is connected to ending TVA? <TAB> 28 # connected ending TVAs <TAB> 29 Number of Neighbors within 10px <TAB> 30 Number of Neighbors within 30px <TAB> 31 Number of Neighbors within 50px \n";
    unsigned int n_FAs = w->get_cell_model()->get_force_transmissions().size();
    ActiveCableModel_FA * acm = (ActiveCableModel_FA*) w->get_cell_model();
    for(unsigned int i=0;i<n_FAs;i++)
    {
    	Ellipse * el = (Ellipse *) w->get_cell_model()->get_force_transmissions()[i]->get_shape();
    	out << i << "\t";
    	out << el->get_area() << "\t";
    	out << el->get_orientation_angle() << "\t";
    	out << el->get_semi_major_axis() << "\t";
    	out << el->get_semi_minor_axis() << "\t";
    	out << el->get_linear_eccentricity() << "\t";
    	out << el->get_eccentricity() << "\t";
    	out << acm->get_force_transmissions()[i]->get_force()[0] << "\t";
    	out << acm->get_force_transmissions()[i]->get_force()[1] << "\t";
    	out << acm->get_force_transmissions()[i]->get_force_magnitude() << "\t";
    	out << (bool) (acm->get_stress_fiber_numbers_at_fa(i).size() > 0) << "\t";
    	out << acm->get_stress_fiber_numbers_at_fa(i).size() << "\t";
    	out << (bool) (acm->get_n_dorsals_at_fa(i) > 0) << "\t";
    	out << acm->get_n_dorsals_at_fa(i) << "\t";
    	out << (bool) (acm->get_n_aeb_at_fa(i) > 0) << "\t";
    	out << acm->get_n_aeb_at_fa(i) << "\t";
    	out << (bool) (acm->get_n_tvas_at_fa(i) > 0) << "\t";
    	out << acm->get_n_tvas_at_fa(i) << "\t";
    	out << el->get_center()[0] << "\t";
    	out << el->get_center()[1] << "\t";
    	out << (bool) (acm->get_stress_fiber_numbers_ending_at_fa(i).size() > 0) << "\t";
    	out << acm->get_stress_fiber_numbers_ending_at_fa(i).size() << "\t";
    	out << (bool) (acm->get_n_dorsals_ending_at_fa(i) > 0) << "\t";
    	out << acm->get_n_dorsals_ending_at_fa(i) << "\t";
    	out << (bool) (acm->get_n_aeb_ending_at_fa(i) > 0) << "\t";
    	out << acm->get_n_aeb_ending_at_fa(i) << "\t";
    	out << (bool) (acm->get_n_tvas_ending_at_fa(i) > 0) << "\t";
    	out << acm->get_n_tvas_ending_at_fa(i) << "\t";
    	out << ForceTransmission::get_number_of_neighbors(w->get_cell_model()->get_force_transmissions(),i,10.0) << "\t";
    	out << ForceTransmission::get_number_of_neighbors(w->get_cell_model()->get_force_transmissions(),i,30.0) << "\t";
    	out << ForceTransmission::get_number_of_neighbors(w->get_cell_model()->get_force_transmissions(),i,50.0) << "\n";
   }
    out.close();
}
